package com.ruoyi.dispatch.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.dispatch.vo.DrivingMonthPlanVO;
import com.ruoyi.framework.utils.BeanCopyUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dispatch.domain.DrivingMonthPlan;
import com.ruoyi.dispatch.service.IDrivingMonthPlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 掘进月计划Controller
 * 
 * @author wuxiaofang
 * @date 2025-05-19
 */
@RestController
@RequestMapping("/dispatch/drivingMonthPlan")
@Anonymous
public class DrivingMonthPlanController extends BaseController
{
    @Autowired
    private IDrivingMonthPlanService drivingMonthPlanService;

    /**
     * 查询掘进月计划列表
     */
    @PreAuthorize("@ss.hasPermi('dispatch:drivingMonthPlan:list')")
    @GetMapping("/list")
    public TableDataInfo list(DrivingMonthPlan drivingMonthPlan)
    {
        startPage();
        List<DrivingMonthPlan> list = drivingMonthPlanService.selectDrivingMonthPlanList(drivingMonthPlan);
        return getDataTable(list);
    }

    /**
     * 导出掘进月计划列表
     */
    @PreAuthorize("@ss.hasPermi('dispatch:drivingMonthPlan:export')")
    @Log(title = "掘进月计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DrivingMonthPlan drivingMonthPlan)
    {
        List<DrivingMonthPlan> list = drivingMonthPlanService.selectDrivingMonthPlanList(drivingMonthPlan);
        ExcelUtil<DrivingMonthPlan> util = new ExcelUtil<DrivingMonthPlan>(DrivingMonthPlan.class);
        util.exportExcel(response, list, "掘进月计划数据");
    }

    /**
     * 获取掘进月计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('dispatch:drivingMonthPlan:query')")
    @GetMapping(value = "/{drivingMonthPlanId}")
    public AjaxResult getInfo(@PathVariable("drivingMonthPlanId") Long drivingMonthPlanId)
    {
        return success(drivingMonthPlanService.selectDrivingMonthPlanByDrivingMonthPlanId(drivingMonthPlanId));
    }

    /**
     * 新增掘进月计划
     */
    @PreAuthorize("@ss.hasPermi('dispatch:drivingMonthPlan:add')")
    @Log(title = "掘进月计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DrivingMonthPlan drivingMonthPlan)
    {
        return toAjax(drivingMonthPlanService.insertDrivingMonthPlan(drivingMonthPlan));
    }

    /**
     * 修改掘进月计划
     */
    @PreAuthorize("@ss.hasPermi('dispatch:drivingMonthPlan:edit')")
    @Log(title = "掘进月计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DrivingMonthPlan drivingMonthPlan)
    {
        return toAjax(drivingMonthPlanService.updateDrivingMonthPlan(drivingMonthPlan));
    }

    /**
     * 删除掘进月计划
     */
    @PreAuthorize("@ss.hasPermi('dispatch:drivingMonthPlan:remove')")
    @Log(title = "掘进月计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{drivingMonthPlanIds}")
    public AjaxResult remove(@PathVariable Long[] drivingMonthPlanIds)
    {
        return toAjax(drivingMonthPlanService.deleteDrivingMonthPlanByDrivingMonthPlanIds(drivingMonthPlanIds));
    }

    /**
     * 生成指定月份掘进月计划数据
     * @param month
     * @return
     */
    @RequestMapping("/genDrivingMonthPlan")
    public AjaxResult genDrivingMonthPlan(String month){
        List<DrivingMonthPlan> monthPlanList = drivingMonthPlanService.copyLastMonthPlan(month);
        List<DrivingMonthPlanVO> vo = BeanCopyUtils.copyListProperties(monthPlanList, DrivingMonthPlanVO.class);
        return toAjax(vo.size(),vo);
    }
}
